package com.itheima.blog.auth.service;

import com.itheima.blog.auth.dto.LoginReqDto;
import com.itheima.blog.auth.dto.LoginResDTO;
import com.itheima.blog.util.constants.Constants;
import com.itheima.blog.util.constants.ErrorInfo;
import com.itheima.common.exception.BlogException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class LoginService {

    @Autowired
    private AdminUserService adminUserService;

    @Autowired
    private WebUserService webUserService;

    /**
     * 登录
     * */
    public LoginResDTO login(LoginReqDto dto) {
        // 如果是admin登录
        if(Objects.equals(dto.getUserType(), Constants.USER_TYPE_ADMIN)){
            return adminUserService.login(dto);
        }else if(Objects.equals(dto.getUserType(), Constants.USER_TYPE_WEB)){
            // 门户用户登录
            return webUserService.login(dto);
        }else{
            throw new BlogException(ErrorInfo.Msg.INVALID_LOGIN_TYPE);
        }
    }
}
